var webpack = require('webpack')
var path = require('path')
var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  entry: {
    vendor:['jquery','bootstrap'],
    app: [
    'webpack-dev-server/client?http://localhost:8888',
    'webpack/hot/only-dev-server',
    './app/src_dev/js/app.js'
    ]
  },
  output: {
    path: path.join(__dirname,'app/src'),
    publicPath: 'http://localhost:8888/assets/',
    filename: '[name].js'
  },
  resolve: {
    root:[path.join(__dirname, 'app/src_dev/vendor')],
    extensions: ['', '.js', '.jsx', '.css'],
    alias:{
      app:      path.join(__dirname, './app/src_dev'),
    	vendor:   path.join(__dirname, './app/src_dev/vendor'),
      dist:     path.join(__dirname, './app/src/'),
      src:      path.join(__dirname, './app/src_dev'),

      // 常用库
    }
  },
  module: {
    loaders: [{
        // 项目js
        test: /\.js$/,
        loaders: ['script-loader','babel-loader'],
        include: path.join(__dirname, 'app/src_dev'),
        exclude: [path.join(__dirname,'node_modules'),path.join(__dirname,'app/src_dev/vendor'),path.join(__dirname,'app/src_dev/js/app.js')]
      },{
        // 入口js
        test: /\.js$/,
        loaders: ['babel-loader'],
        include: path.join(__dirname,'app/src_dev/js/app.js'),
      },{
        // 第三方js
        test: /\.js$/,
        loaders: [],
        include: [path.join(__dirname,'node_modules'),path.join(__dirname,'app/src_dev/vendor')],
      },{
        test: /\.css$/,
        loader: ExtractTextPlugin.extract('style-loader','css-loader!autoprefixer-loader')
      },{
        test: /\.(sass|scss)$/,
        loader: ExtractTextPlugin.extract('style-loader','css-loader!autoprefixer-loader!sass-loader')
      },{
        test: /\.less$/,
        loader: ExtractTextPlugin.extract('style-loader','css-loader!autoprefixer-loader!less-loader')
      },{
        test: /\.(png|jpg|jpeg)$/,
        loader: 'url-loader?limit=8192'
      },{
        test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: "url-loader?limit=10000&minetype=application/font-woff"
      },{
        test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: "file-loader"
      }
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    // 打包公共库
    // new webpack.optimize.CommonsChunkPlugin({
    //   name: "vendor",
    //   filename: "vendor.js"
    // }),
    // bower 文件
    new webpack.ResolverPlugin(
        new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
    ),
    // 全局变量
    // new webpack.ProvidePlugin({
    //     $: "jquery",
    //     jQuery:'jquery',
    // }),
    // css 文件单独打包
    new ExtractTextPlugin("style.css", {
        allChunks: true
    }),
    // 压缩 js
    // new webpack.optimize.UglifyJsPlugin({
    //     compress: {
    //         warnings: false
    //     }
    // })
  ]
};
